package org.Tools;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Random;

public class TestTools {
    public static void testRandom() {
        Random r = new Random();
        System.out.printf("Random nextInt %X \n", r.nextInt());
        System.out.printf("Random nextInt[0,%d) %d \n", 10, r.nextInt(10));
        System.out.println("Long.parseUnsignedLong = "+ Long.parseUnsignedLong("668899"));
        System.out.printf("Random nextLong %X \n", r.nextLong() );
        System.out.printf("Random nextFloat %f \n", r.nextFloat());
        System.out.printf("Random nextDouble %f \n", r.nextDouble());
    }

    public static void testSecureRandom() {
        SecureRandom sr = null;
        try {
            sr = SecureRandom.getInstanceStrong(); // 获取高强度安全随机数生成器
        } catch (NoSuchAlgorithmException e) {
            sr = new SecureRandom(); // 获取普通的安全随机数生成器
        }
        byte[] buffer = new byte[16];
        sr.nextBytes(buffer); // 用安全随机数填充buffer
        System.out.println(Arrays.toString(buffer));
    }
}
